package com.example.demo.servlet;

import com.example.demo.dao.BookDao;
import com.example.demo.entity.BookVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/addbook")
public class Addbook extends HttpServlet{
    BookVo bookVo =new BookVo();

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           try{
               String bookname = request.getParameter("bookname");

               bookVo.setTitle(bookname);
               String author = request.getParameter("author");
               bookVo.setAuthor(author);
               String price = request.getParameter("price");
               bookVo.setPrice(Double.parseDouble(price));
               String stock = request.getParameter("number");
               System.out.println(bookname);
               bookVo.setStock(Integer.valueOf(stock));
//               String bookid = request.getParameter("bookid");
//               bookVo.setBookid(Integer.valueOf(bookid));

               new BookDao().saveBook(bookVo);
               request.getRequestDispatcher("/getbooks").forward(request,response);
           } catch (Exception e) {
               throw new RuntimeException(e);
           }
        }
}
